home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_08_10
/
8n10109a
< prev
next >
Wrap
Text File
|
1990-07-01
|
2KB
|
52 lines
// mandel.c - Zortech C++ program to draw Mandelbrot set.
#include <conio.h>
#include "fg.h"
#include "dcomplex.h"
inline float scale(int point, int maxpoint)
{
maxpoint /= 2;
return 2 * (point - maxpoint)/float(maxpoint);
}
int resolution = 50;
int maxrow;
int maxcol;
int mandel(float row, float col)
{
DComplex Z(0,0);
DComplex C(col, row);
int color = 0;
for(int iter = 0; iter < resolution && abs(Z) < 2.0; ++iter, ++color)
Z = Z * Z + C;
return iter < resolution ? color : 0;
}
int main(int argc, char **argv)
{
int status = fg_init(); // initialize graphics package
maxrow = fg.displaybox[FG_Y2];
maxcol = fg.displaybox[FG_X2];
int maxcolor = fg.nsimulcolor;
if(status != 0)
{
int step = 20;
for(resolution = 1; !kbhit(); ++resolution)
{
for(int col=maxcol; col >= 0 && !kbhit(); col -= step)
for(int row = 0; row <= maxrow/2; row += step)
{
int color = mandel(scale(row,maxrow),
scale(col,maxcol))
% maxcolor;
fg_drawdot(color, FG_MODE_SET, ~0, col, row);
fg_drawdot(color, FG_MODE_SET, ~0, col, maxrow-row);
}
if(step > 1) --step;
}
while(!kbhit()) // hit key to terminate program
;
fg_term(); // return to text mode
}
}